home *** CD-ROM | disk | FTP | other *** search
- #pragma mark Header
- /***************************/
- /* Generic.c
- This program is to demonstrate some
- of the generic features of THINK C
- and some of the THINK C features for
- debugging and console emulation
- History
- 6/5/91 - Created by Kirk Chase */
- /***************************/
-
- #pragma mark #includes
- /* the #pragma directive is ignored by THINK C and is used
- by CMarker by Max Lyth (shareware $20). CMarker adds a
- box to the window bar that when pressed will display a
- list of all functions and #pragma mark <Name> directives.
- This is useful for quick navigation through a source file.
- You simply select the function or <Name>, and the window
- will scroll to it. Also you can comment/uncomment blocks
- of code. */
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <time.h>
- #include "DebugAids.h"
-
- #ifdef THINK_C
- #include <console.h>
- #endif
-
- #ifdef PROFILE
- #include <profile.h>
- #endif
-
- #pragma mark #defines
- #ifndef TRUE
- #define TRUE (1)
- #define FALSE (0)
- #endif
-
- #pragma mark Globals
- jmp_buf env;
-
- void PrintMenu(void)
- /* prints menu choices */
- {
- printf("\n");
- #ifdef THINK_C
- printf("\n\t\tΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩ\n");
- printf("\t\t™™ MAIN MENU ™™\n");
- printf("\t\tΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩ\n\n");
-
- printf("†Ã† Command Line Args\t\t");
- printf("†¬† Beep Macintosh\n");
- printf("†‘† Test Interrupt\t\t");
- printf("†¡† Advertisement\n");
- printf("†“† Read File\t\t\t");
- printf("†√† Copy File\n");
- printf("†±† Test Page 1\t\t\t");
- printf("†≤† Test Page 2\n");
-
- printf("\n†—† Quit\n");
- #else
- printf("\n\t\t===============\n");
- printf("\t\t** MAIN MENU **\n");
- printf("\t\t===============\n\n");
-
- printf(" L) Command Line Args\t\t");
- printf(" B) Beep Macintosh\n");
- printf(" T) Test Interrupt\t\t");
- printf(" A) Advertisement\n");
- printf(" R) Read File\t\t\t");
- printf(" C) Copy File\n");
- printf(" 1) Test Page 1\t\t\t");
- printf(" 2) Test Page 2\n");
-
- printf("\n Q) Quit\n");
- #endif
- }
-
- char GetChoice(void)
- /* gets menu choices */
- {
- char command;
- char commandSet[10] = "QBTRCLA12\0";
- #ifdef PROFILE
- _profile = FALSE;
- _trace = FALSE;
- #endif
- printf("\n");
-
- #ifdef THINK_C
- csetmode(C_CBREAK, stdin);
- printf("æææ ");
- #else
- printf(">>> ");
- #endif
-
- scanf("%c", &command);
- command = toupper(command);
- while (!strchr(commandSet, command)) { /* loop til command is valid */
- printf("\nType in one of the following letters <%s>\n", commandSet);
-
- #ifdef THINK_C
- printf("\næææ ");
- #else
- printf(">>> ");
- #endif
- scanf("%c", &command);
- command = toupper(command);
- }
- printf("\n");
-
- #ifdef THINK_C
- csetmode(C_ECHO, stdin);
- #endif
- #ifdef PROFILE
- _profile = TRUE;
- _trace = TRUE;
- #endif
- return (command);
- }
-
- void TestInterrupt(void)
- /* continous loop until cmd-. is pressed */
- {
- while (!CheckOptionAbort()) printf("Type COMMAND-. to stop!\n");
- }
-
- main(int argc, char **argv)
- {
- /* main entry point */
- short i, theSignal;
- char com;
- FILE *con2=NULL;
-
- /* set up */
- #ifdef PROFILE
- InitProfile(200, 200);
- _profile = TRUE;
- _trace = TRUE;
- #endif
-
- #ifdef THINK_C
- /* This should go up all the time unless using another environment */
- argc = ccommand(&argv);
- cinverse(TRUE, stdout);
- ccleos(stdout);
- printf("You are using THINK C\n");
- #else
- printf("You are using a PC\n");
- #endif
-
- #ifdef DEBUG
- printf("Debug options are on\n");
- #else
- printf("Debug options are off\n");
- #endif
-
- #ifdef DEBUGGER
- printf("Debugger options are on\n");
- #else
- printf("No Debugger\n");
- #endif
-
- printf("\n");
-
- /* set up second console */
- InitSecondConsole(&con2);
-
- do { /* main loop */
- #ifdef PROFILE
- _profile = FALSE;
- _trace = FALSE;
- #endif
-
- theSignal = setjmp(env); /* set up jump point */
- SigHandler(theSignal); /* do signal handler */
-
- PrintMenu();
- com = GetChoice();
-
- #ifdef PROFILE
- _profile = TRUE;
- _trace = TRUE;
- #endif
-
- switch (com) { /* handle command */
- case 'B':
- printf("\a"); /* '\a' rings bell/beeps Macintosh */
- break;
- case 'T':
- #ifdef PROFILE
- _profile = FALSE; /* cmd-. messes up profiler */
- _trace = FALSE;
- #endif
-
- TestInterrupt(); /* test cmd-. */
-
- #ifdef PROFILE
- _profile = TRUE;
- _trace = TRUE;
- #endif
-
- break;
- case 'R':
- ReadFile(FALSE, con2); /* read a file */
- break;
- case 'C':
- ReadFile(TRUE, con2); /* copy a file */
- break;
- case 'L': /* list command line arguements */
- printf(" #\tArguement\n==\t=========\n");
- for (i=0; i<argc; i++)
- printf("%d\t%s \n", i, argv[i]);
-
- #ifdef THINK_C
- printf("\nPress mouse button to continue...\n\n");
- while(!Button()); /* loop until button */
- #endif
- break;
- case 'A':
- SecondConsoleAd(con2); /* advertisement */
- break;
- case '1': /* print columns/rows per page */
- case '2': /* print two pages with forced page break */
- PrintTestPage((short) com - '0');
- break;
- }
- } while (com != 'Q');
-
- #ifdef PROFILE
- #ifdef THINK_C
- cecho2file("Profiler Report", TRUE, stdout); /* output to file */
- #endif
- printf("***** Profile Report *****\n");
- printf("%s\n", ctime(NULL));
- #endif
- }